package cn.kone.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.kone.pojo.domain.DriverAuthMaterial;
import cn.kone.pojo.dto.LocationDTO;
import cn.kone.result.JSONResult;
import cn.kone.service.IDriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "微信注册", description = "微信注册的接口")
@RestController
@RequestMapping("/app/driver")
public class WeChatRegisterDriverController {



    @Autowired
    private IDriverService driverService;



    /**
     * 通过前端传递的Code获取openid完成微信注册
     * @param code
     * @return 将获取到的openid统一封装到JSONResult中返回给前端
     */
    @Operation(summary = "微信注册", description = "获取openid")
    @Parameter(name = "code", description = "获取openid", required = true)
    @GetMapping("/openid")
    @SaIgnore
    public JSONResult getOpenId(String code) {
        return JSONResult.success(driverService.getOpenId(code));
    }

    /**
     * 司机实名认证
     * @param driverAuthMaterial
     * @return
     */
    @Operation(summary = "司机提交实名", description = "司机提交实名材料")
    @Parameter(name = "实名材料", description = "提交的实名材料", required = true)
    @PostMapping("/submit")
    public JSONResult submitRealNameMaterial(@RequestBody DriverAuthMaterial driverAuthMaterial) {
        return JSONResult.success(driverService.submitRealNameMaterial(driverAuthMaterial));
    }

    /**
     * 获取实名审核的状态
     * @return 返回审核状态
     */
    @Operation(summary = "获取实名审核状态", description = "实名审核状态")
    @Parameter(name = "实名审核状态", description = "实名审核状态", required = true)
    @GetMapping("/getsubmit")
    public JSONResult getSubmitRealNameMaterial() {
        return JSONResult.success(driverService.getSubmitRealNameMaterial());
    }

    /**
     * 查询司机概要
     */
    @Operation(summary = "查询司机概要", description = "查询司机概要情况")
    @Parameter(name = "查询司机概要", description = "查询司机概要", required = true)
    @GetMapping("/getsummary")
    public JSONResult getSummary() {
        return JSONResult.success(driverService.getSummary());
    }

    /**
     * 司机上线将配置缓存到Redis中
     * @return
     */
    @PostMapping("/online")
    public JSONResult onLine(){
        return JSONResult.success(driverService.getOnline());
    }

    /**
     * 司机下线将Redis中的司机配置删除
     * @return
     */
    @PostMapping("/offline")
    public JSONResult offLine(){
        return JSONResult.success(driverService.offLine());
    }


    /**
     * 司机下线将Redis中的司机配置删除
     * @return
     */
    @PostMapping("/geo")
    public JSONResult saveGeo(@RequestBody LocationDTO locationDTO){
        return JSONResult.success(driverService.saveGeo(locationDTO));
    }
}
